

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>商品展示</title>
    <link rel="stylesheet" href="../static/dist/css/layui.css">
    <style>
        .goods-container {
            display: flex;
            flex-wrap: wrap;
            justify-content: space-between;
            margin: -10px;
        }

        .layui-card {
            flex: 0 0 calc(25% - 20px); /* 25%宽度，减去margin和border的20px */
            text-align: center;
            margin: 10px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            transition: box-shadow 0.3s ease-in-out;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
        }

        .layui-card:hover {
            box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
        }

        .layui-card-img-top {
            width: 100%;
            height: 400px;
            object-fit: cover;
            margin: 0 auto;
        }


        .layui-card-body {
            padding: 0px;
        }
    </style>
</head>
<body>
<div class="layui-container">
    <div class="goods-container" id="goodsList">

    </div>
</div>

<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript" src="../static/dist/layui.js"></script>
<script type="text/javascript">
    layui.use('jquery', function(){
        var $ = layui.jquery;

        function loadGoodsByType() {
            $.ajax({
                url: "http://127.0.0.1:5000/goodthing", // 请根据实际接口地址修改
                type: "GET",
                success: function(response) {
                    var goodsData = response.data; // 假设返回的数据在 response.data 中
                    var goodsHtml = '';
                    for (var i = 0; i < goodsData.length; i++) {
                        var goods = goodsData[i];
                        goodsHtml += '<div class="layui-card">';
                        goodsHtml += '<a href="' + goods.link_url + '">';
                        goodsHtml += '<img src="' + goods.img_url + '" alt="' + goods.name + '" class="layui-card-img-top">';
                        goodsHtml += '<div class="layui-card-body">';
                        goodsHtml += '</div>';
                        goodsHtml += '</a>';
                        goodsHtml += '</div>';
                    }
                    $('#goodsList').html(goodsHtml);
                },
                error: function(error) {
                    alert("没有得到商品数据");
                }
            });
        }

        // 页面加载完成后调用加载商品数据的函数
        $(document).ready(function() {
            loadGoodsByType();
        });
    });
</script>
</body>
</html>
